<template>
  <div class="login-page">
    <div class="login-container">
      <div class="title">
        <div class="title-style">
          <div>商业街区地理空间数据管理demo</div>
          <div class="sub-title">—— 以厦门市岛内为例</div>
        </div>
      </div>

      <div class="login">
        <el-card>
          <el-form :model="validateForm" ref="validateForm">
            <el-form-item
              label="账号"
              prop="account"
              :rules="[{ required: true, message: '账号不能为空' }]"
            >
              <el-input
                v-model="validateForm.account"
                placeholder="请输入账号"
              ></el-input>
            </el-form-item>
            <el-form-item
              label="密码"
              prop="password"
              :rules="[{ required: true, message: '密码不能为空' }]"
            >
              <el-input
                v-model="validateForm.password"
                placeholder="请输入密码"
                show-password
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button style="width: 100%" type="primary" @click="submitForm">
                登录
              </el-button>
            </el-form-item>
          </el-form>
          <div class="jump">
            <a :href="bigScreenUrl" target="_blank">前往大屏</a>
          </div>
        </el-card>
      </div>
    </div>

    <div class="foot">
      <span style="margin-right: 30px">作者：Linh</span>
      <span style="margin-right: 30px">版本：V0.01</span>
      <span style="margin-right: 30px">邮箱：307148762@qq.com</span>
      <span>微信：15280375031</span>
    </div>
  </div>
</template>

<script>
import { login } from "@/api/httpApi";
import { bigScreenUrl } from "@/config/config";

export default {
  data() {
    return {
      validateForm: {
        account: "",
        password: "",
      },
      bigScreenUrl,
    };
  },
  methods: {
    submitForm() {
      this.$refs.validateForm.validate(async (valid) => {
        if (valid) {
          let res = await login(this.validateForm);
          if (res.status === 200) {
            window.localStorage.setItem("userinfo", JSON.stringify(res.data));
            window.localStorage.setItem("token", res.token);
            this.$router.push("/index");
            this.$message.success("登录成功");
          } else {
            this.$message.error(`${res.mes}`);
          }
        } else {
          this.$message.error("请输入账号密码");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.login-page {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: linear-gradient(135deg, #ece9e6, #ffffff);
}
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  padding: 5%;
  width: 45%;
  background-size: cover;
  background-image: linear-gradient(
      to left,
      rgba(0, 0, 0, 0.3),
      rgba(255, 255, 255, 0)
    ),
    url("@/assets/bg.png");
  border-radius: 6px 6px 6px 6px;
  box-shadow: 10px 10px 10px 10px rgba(0, 0, 0, 0.1);
}
.title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.title-style {
  padding: 20px;
  background: #2b6695;
  border-radius: 6px 6px 6px 6px;
  box-shadow: 2px 2px 2px 2px rgba(0, 0, 0, 0.1);
  color: #ffffff;
  font-size: 30px;
  font-weight: bold;
  text-shadow: 2px 2px 3px #222222;
}
.sub-title {
  margin-top: 10px;
  font-size: 16px;
  text-align: end;
}
.login {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding-left: 10%;
}
.foot {
  position: absolute;
  bottom: 10%;
  background-color: #e0e0e0;
  padding: 5px 30px 5px 30px;
  border-radius: 50px;
  color: #9e9e9e;
}
.jump {
  display: flex;
  justify-content: flex-end;
}
</style>